// Created by WXX on 2021/9/6 9:09
#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    int search(vector<int> &nums, int target) {
        int l = 0, r = nums.size() - 1;
        while (l < r) {
            int mid = l + r >> 1;
            if (nums[mid] >= target) r = mid;
            else l = mid + 1;
        }
        if (nums[r] == target) return r;
        return -1;
    }
};

int main() {

    vector<int> nums = {-1, 0, 3, 5, 9, 12};
    cout << Solution().search(nums, 9) << endl;  // 4

    return 0;
}
